package com.sun.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;

/**
 * 引⼊Xml消息转换器
 * 在传统Spring应⽤中，我们可以通过如下配置加⼊对Xml格式数据的消息转换实现
 *
 * Spring MVC中默认已经有⼀套采⽤Jackson实现的转换器 MappingJackson2XmlHttpMessageConverter
 * @author Administrator
 */
@Configuration
public class MessageConverterConfig1 extends WebMvcConfigurerAdapter {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {

        Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.xml();
        builder.indentOutput(true);
        converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
    }
}
